import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
var _excluded = ["children", "title", "code", "lang"];

var _dec, _dec2, _class;

import React, { Component } from 'react';
import { Bind } from 'lodash-decorators';
import { Tooltip } from 'antd';
import { queryToolTip } from "../../services/api";
import StaticTextEditor from "./StaticTextEditor";
import styles from "./index.less?modules";
var Tips = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_Component) {
  _inherits(Tips, _Component);

  var _super = _createSuper(Tips);

  function Tips(props) {
    var _this;

    _classCallCheck(this, Tips);

    _this = _super.call(this, props);
    _this.staticTextEditor = React.createRef();
    _this.state = {
      prevContent: '',
      prevTitle: '',
      visible: false
    };
    return _this;
  }

  _createClass(Tips, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      var _this$props = this.props,
          code = _this$props.code,
          lang = _this$props.lang;
      queryToolTip({
        textCode: code,
        lang: lang
      }).then(function (res) {
        if (res) {
          _this2.setState({
            prevContent: res.text,
            prevTitle: res.title
          });
        } else {
          _this2.setState({
            prevContent: '',
            prevTitle: ''
          });
        }
      });
    }
  }, {
    key: "handleVisible",
    value: function handleVisible() {
      var visible = this.state.visible;
      this.setState({
        visible: visible
      });
    }
  }, {
    key: "renderRichEditor",
    value: function renderRichEditor() {
      var _this3 = this;

      var _this$state = this.state,
          prevContent = _this$state.prevContent,
          prevTitle = _this$state.prevTitle;
      var title = this.props.title;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
        style: {
          textAlign: 'center'
        }
      }, title || prevTitle), /*#__PURE__*/React.createElement(StaticTextEditor, {
        content: prevContent,
        readOnly: true,
        onRef: function onRef(staticTextEditor) {
          _this3.staticTextEditor = staticTextEditor;
        }
      }));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          children = _this$props2.children,
          title = _this$props2.title,
          code = _this$props2.code,
          lang = _this$props2.lang,
          others = _objectWithoutProperties(_this$props2, _excluded);

      return /*#__PURE__*/React.createElement(Tooltip, Object.assign({
        trigger: "click",
        overlayClassName: styles['editor-tooltip']
      }, others, {
        title: this.renderRichEditor()
      }), children);
    }
  }]);

  return Tips;
}(Component), (_applyDecoratedDescriptor(_class.prototype, "handleVisible", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleVisible"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "renderRichEditor", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "renderRichEditor"), _class.prototype)), _class));
export { Tips as default };